﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using PccCommonForC;
using System.Xml;
using System.Text;
using System.IO;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Text.RegularExpressions;
using bs_ShowRoom;
using System.Configuration;
using System.Collections;
using System.Security.Cryptography;
using System.Net.Mail;
namespace ShowRoom.admin
{
    public partial class UpdatePass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            
            string user_id = "0";
           
            string Type = "3";
            string email = txtEmail.Text.ToString().Trim();

            string ok = SaveData(user_id, "", "aaaaaa", "", "", email, "", "", "", "", "N", "", "", Type);
            if (ok == "")
            {
                string Mes ="Cập nhật thành công !";
                string url = "user.aspx";
                // Response.Write("<script>alert('Quý khách đã đăng ký thành công tài khoản tại showroommypham.com !');window.location='login.aspx?&name=" + txtuser.Text.ToString().Trim() + "'</script>");
                ScriptFunction.ShowMsgTranOpennerUrl_ScriptManager(Mes, Page, url);
            }
            else
            {
                Response.Write("<script>alert('Đả có lỗi xãy ra trong quá trình đăng ký !')</script>");
                return;
            }
        }
        #region "Save Data"
        public string SaveData(string user_id, string user_name, string password, string name, string phone, string email, string sex, string introduction, string adress, string birthday, string activeEmail, string emailPass, string active, string Type)
        {
            bs_user myBs = new bs_user(ConfigurationManager.ConnectionStrings["ShowRoomConnectionString"].ToString());
            PccMsg myMsg = new PccMsg();
            myMsg.CreateFirstNode("user_id", user_id);
            myMsg.CreateFirstNode("name", name);
            myMsg.CreateFirstNode("username", user_name);
            myMsg.CreateFirstNode("password", password);
            myMsg.CreateFirstNode("ipassword", password);
            myMsg.CreateFirstNode("email", email);
            myMsg.CreateFirstNode("adress", adress);
            myMsg.CreateFirstNode("birthday", birthday);
            myMsg.CreateFirstNode("telephone", phone);
            myMsg.CreateFirstNode("sex", sex);
            myMsg.CreateFirstNode("company", "");
            myMsg.CreateFirstNode("point", "10");
            myMsg.CreateFirstNode("note", introduction);
            myMsg.CreateFirstNode("activeEmail", activeEmail);
            myMsg.CreateFirstNode("emailPass", EncryptMD5(emailPass));
            myMsg.CreateFirstNode("active", active);
            myMsg.CreateFirstNode("Type", Type);
            string strXML = myMsg.GetXmlStr;
            string strReturn = myBs.DoReturnStr("INSUPDUSER", strXML, "");
            myMsg.LoadXml(strReturn);


            return myMsg.Query("Err");
        }

        #endregion

        #region Ma Hoa Pass
        public static string EncryptMD5(string cleanString)
        {
            Byte[] clearBytes = null;
            clearBytes = new UnicodeEncoding().GetBytes(cleanString);
            Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
            string hashedText = BitConverter.ToString(hashedBytes);
            return hashedText;
        }
        #endregion
    }
}